Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		number: 0,
		globalNo: 0,
		totalAmount: 0,
		selectCardUrl:[
			'/image/1.jpg',
			'/image/2.jpg',
			'/image/3.jpg', 
			'/image/4.jpg',
			'/image/5.jpg',
			'/image/6.jpg'
		],
		currentId: 0,
		currentItem: '/image/1.jpg',
		giftList:[
			{
				id: 1,
				title:'诶诶诶诶诶',
				price:100,
				number:0
			},
			{
				id: 2,
				title: '哔哔哔哔哔',
				price: 200,
				number: 0
			},
			{
				id: 3,
				title: '谁谁谁谁谁',
				price: 300,
				number: 0
			},
		]
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
		
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {
		
	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {
		
	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		
	},

	/*
	 * 点击小卡片切换 
	 */

	changeCad: function (event) {
		this.setData({
			currentId: event.currentTarget.id,
			currentItem: this.data.selectCardUrl[event.currentTarget.id]	
		});
	},

	/*
	* 加减商品数量
	*/

	plus: function (event) {
		let index = event.currentTarget.dataset.number;
		let newGiftList = this.data.giftList;
		let newNo = newGiftList[index].number;
		newNo++;
		newGiftList[index].number = newNo;
		this.setData({
			changePlusBg: false,
			giftList: newGiftList,
			globalNo: this.data.globalNo + 1,
			totalAmount: this.data.totalAmount + newGiftList[index].price
		});
	},

	subtract: function (event) {
		let index = event.currentTarget.dataset.number;
		let newGiftList = this.data.giftList;
		let newNo = newGiftList[index].number;
		newNo--;
		newGiftList[index].number = newNo;
		this.setData({
			giftList: newGiftList,
			globalNo: this.data.globalNo - 1,
			totalAmount: this.data.totalAmount - newGiftList[index].price
		});
	}

})